

cc.Class({
    extends: cc.Component,

    properties: {
    //激光    
    laser:cc.Prefab,
    //boss子弹
    boss_bullet:cc.Prefab,
    //爆炸特效
    bang:cc.Prefab,
    //boss死亡特效
    boss_bang:cc.Prefab,
    },

    

     onLoad () {
       this.hp = 10000;  
       this.isplace = false;
     },

    start () {

    },

    init:function(){
        //生成激光
        this.isplace = true;
        this.node.hp = this.hp;
        let laser = cc.instantiate(this.laser); 
        this.node.addChild(laser);
        laser.setPosition(cc.p(0,-this.node.height / 2 - laser.height / 2));       
        laser.type = 2;
    //生成散弹
    this.schedule(this.make_bullet,1);
    //随机移动
    this.schedule(this.enemy_plane_move,2);

    },

    //随机移动
    enemy_plane_move:function(){
    var randx = window.Global.getRandom(-10,10);
    this.node.runAction(cc.moveBy(2,cc.p(randx,0)));
    },

    //生成子弹
    make_bullet:function(){
    for(let i = 0; i < 19; i++){
        var enmey_bullet = window.Global.getClassAndAdd(this.boss_bullet,"Enemy_bullet",this.node.parent); 
        if(i < 10){
            this.rotation = 10 * i;
        }else{
            this.rotation = -10 * (i - 9);
        }
       
        enmey_bullet.tClass.init(3,this.rotation);  
        enmey_bullet.tNode.setPosition(this.node.position);
     }
    },
    //碰撞检测
    onCollisionEnter:function(other,self){
        if(self.node.hp <= 0){
            window.Global.score +=  250;
            window.Global.Stage_score += 250;
            self.node.children[0].getComponent(cc.ProgressBar).Progress = self.node.hp / this.hp;
            let boss_bang = window.Global.getClassAndAdd(this.boss_bang,"Bang",self.node);
            window.Global.Bullet_hit = false;
            window.Global.isstartgame = true;
            self.node.destroy();   
            
        }
        if(this.isplace){
            if(other.node.group == "bullet"){

                self.node.children[0].active = true;
                self.node.hp -= 100;
    
                self.node.children[0].getComponent(cc.ProgressBar).progress = self.node.hp / this.hp;
               
                let bang = window.Global.getClassAndAdd(this.bang,"Bang",this.node.parent);
                bang.tNode.setPosition(other.node.position);  
                other.node.destroy();   

            }
            
        }
        
    },
 
   
    
});
